n = int(input())
nums = [int(x) for x in input().split(" ")]


def canThreePartsEqualSum(arr):
    arrSum = sum(arr)
    if arrSum % 3 != 0:
        return False
    singleSum = arrSum // 3
    cnt = 3
    tempSum = 0
    for i in arr:
        if tempSum + i == singleSum:
            if cnt > 0:
                cnt -= 1
                tempSum = 0
            else:
                tempSum += i
        else:
            tempSum += i
    if cnt == 0 and tempSum == 0:
        return True
    else:
        return False

print(canThreePartsEqualSum(nums))